#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

vector<vector<int>> count(vector<int> array){
    vector<vector<int>> result;
    for(int i = 0; i < array.size(); ++i){
        for(int j = 0; j < result.size() + 1; ++j){
            if(array[i] != result[j][0] && j == result.size() - 1){
                result.push_back(vector<int>{i, 1});
            }
            if(array[i] == result[j][0]){
                ++result[j][1];
                break;
            }
        }
    }
    return result;
}

/*count_zz : 
入参: 
ar_source  需要计算的数组
出参: 
ar_dest    计算出的不含重复元素的数组
ar_num     和ar_dest对应元素的个数
nMax       计算出的ar_source中最大元素
nNum       计算出的ar_source中最大元素的个数
返回值：
无
*/
void count_zz(const vector<int> &ar_source, vector<int> &ar_dest, vector<int> &ar_num, int &nMax, int &nNum){
    for(vector<int>::const_iterator iter = ar_source.begin(); iter != ar_source.end(); ++iter){
        vector<int>::iterator iter_find;
        
        iter_find = find(ar_dest.begin(), ar_dest.end(), *iter);

        if( iter_find == ar_dest.end() ){
            ar_dest.push_back(*iter);
            ar_num.push_back(1);
        }
        else{
            vector<int>::iterator iter_num;
            int nOffset = iter_find - ar_dest.begin();

            iter_num = ar_num.begin() + nOffset;
            (*iter_num)++;
        }
    }

    nMax = *(ar_dest.begin());
    nNum = *(ar_num.begin());
    
    for(vector<int>::iterator iter_m = ar_dest.begin(); iter_m != ar_dest.end(); ++iter_m){
        if(*iter_m > nMax){
            nMax = *iter_m;
            nNum = *(ar_num.begin() + (iter_m - ar_dest.begin()));
        }
    }
}

int main(int argc, char const *argv[])
{
    vector<int> ar_source{1, 3, 6, 9, 1, 3, 6, 9, 6, 9};
    vector<int> ar_dest, ar_num;
    int nMax, nNum;
    
    count_zz(ar_source, ar_dest, ar_num, nMax, nNum);
    
    for(int i = 0; i < ar_dest.size(); ++i){
        cout << ar_dest[i] << " " << ar_num[i] << endl;
    }

    cout << "max:" << nMax << "; num:" << nNum << endl;

    return 0;
}
